package com.xd.pre.modules.tpshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xd.pre.modules.tpshop.domain.TpCart;
import com.xd.pre.modules.tpshop.domain.TpCoupon;
import com.xd.pre.modules.tpshop.mapper.TpCouponMapper;
import com.xd.pre.modules.tpshop.service.ITpCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@Service
public class TpCouponServiceImpl extends ServiceImpl<TpCouponMapper, TpCoupon> implements ITpCouponService {
    @Autowired
    TpCouponMapper couponMapper;

    @Override
    public TpCoupon findById(Integer couponId) {
        return getById(couponId);
    }

    @Override
    public int update_useNum_increase(int couponId) {
        TpCoupon oo = new TpCoupon();
        oo.setUseNum(oo.getSendNum()+1);
        LambdaQueryWrapper<TpCoupon> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(TpCoupon::getCouponId, couponId);
        int update = couponMapper.update(oo, lambdaQuery);
        return update;
    }
}
